package com.ruoyi.web.controller.safe;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safe.domain.EmergencyRescue;
import com.ruoyi.safe.service.IEmergencyRescueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应急物资和人员Controller
 * 
 * @author yxf
 * @date 2021-08-10
 */
@RestController
@RequestMapping("/safe/rescue")
public class EmergencyRescueController extends BaseController
{
    @Autowired
    private IEmergencyRescueService emergencyRescueService;

    /**
     * 查询应急物资和人员列表
     */
    @PreAuthorize("@ss.hasPermi('safe:rescue:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmergencyRescue emergencyRescue)
    {
        startPage();
        List<EmergencyRescue> list = emergencyRescueService.selectEmergencyRescueList(emergencyRescue);
        return getDataTable(list);
    }

    /**
     * 导出应急物资和人员列表
     */
    @PreAuthorize("@ss.hasPermi('safe:rescue:export')")
    @Log(title = "应急物资和人员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EmergencyRescue emergencyRescue)
    {
        List<EmergencyRescue> list = emergencyRescueService.selectEmergencyRescueList(emergencyRescue);
        ExcelUtil<EmergencyRescue> util = new ExcelUtil<EmergencyRescue>(EmergencyRescue.class);
        return util.exportExcel(list, "应急物资和人员数据");
    }

    /**
     * 获取应急物资和人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('safe:rescue:query')")
    @GetMapping(value = "/{erId}")
    public AjaxResult getInfo(@PathVariable("erId") Long erId)
    {
        return AjaxResult.success(emergencyRescueService.selectEmergencyRescueById(erId));
    }

    /**
     * 新增应急物资和人员
     */
    @PreAuthorize("@ss.hasPermi('safe:rescue:add')")
    @Log(title = "应急物资和人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmergencyRescue emergencyRescue)
    {
        return toAjax(emergencyRescueService.insertEmergencyRescue(emergencyRescue));
    }

    /**
     * 修改应急物资和人员
     */
    @PreAuthorize("@ss.hasPermi('safe:rescue:edit')")
    @Log(title = "应急物资和人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmergencyRescue emergencyRescue)
    {
        return toAjax(emergencyRescueService.updateEmergencyRescue(emergencyRescue));
    }

    /**
     * 删除应急物资和人员
     */
    @PreAuthorize("@ss.hasPermi('safe:rescue:remove')")
    @Log(title = "应急物资和人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{erIds}")
    public AjaxResult remove(@PathVariable Long[] erIds)
    {
        return toAjax(emergencyRescueService.deleteEmergencyRescueByIds(erIds));
    }
}
